home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / GPP257.ZIP / cplusinc / cursesw.h < prev    next >
C/C++ Source or Header  |  1993-11-13  |  14KB  |  577 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2.  
  3. /* 
  4. Copyright (C) 1989 Free Software Foundation
  5.     written by Eric Newton (newton@rocky.oswego.edu)
  6.  
  7. This file is part of the GNU C++ Library.  This library is free
  8. software; you can redistribute it and/or modify it under the terms of
  9. the GNU Library General Public License as published by the Free
  10. Software Foundation; either version 2 of the License, or (at your
  11. option) any later version.  This library is distributed in the hope
  12. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  13. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  14. PURPOSE.  See the GNU Library General Public License for more details.
  15. You should have received a copy of the GNU Library General Public
  16. License along with this library; if not, write to the Free Software
  17. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #ifndef _CursesWindow_h
  21. #ifdef __GNUG__
  22. #pragma interface
  23. #endif
  24. #define _CursesWindow_h
  25.  
  26. #include   <_G_config.h>
  27. #if _G_HAVE_CURSES
  28. #include   <curses.h>
  29.  
  30. /* SCO 3.2v4 curses.h includes term.h, which defines lines as a macro.
  31.    Undefine it here, because CursesWindow uses lines as a method.  */
  32. #undef lines
  33.  
  34. // "Convert" macros to inlines, if needed.
  35. #ifdef addch
  36. inline int (addch)(char ch)  { return addch(ch); }
  37. #undef addch
  38. #endif
  39. #ifdef addstr
  40. /* The (char*) cast is to hack around missing const's */
  41. inline int (addstr)(const char * str)  { return addstr((char*)str); }
  42. #undef addstr
  43. #endif
  44. #ifdef clear
  45. inline int (clear)()  { return clear(); }
  46. #undef clear
  47. #endif
  48. #ifdef clearok
  49. inline int (clearok)(WINDOW* win, int bf)  { return clearok(win, bf); }
  50. #undef clearok
  51. #else
  52. extern "C" int clearok(WINDOW*, int);
  53. #endif
  54. #ifdef clrtobot
  55. inline int (clrtobot)()  { return clrtobot(); }
  56. #undef clrtobot
  57. #endif
  58. #ifdef clrtoeol
  59. inline int (clrtoeol)()  { return clrtoeol(); }
  60. #undef clrtoeol
  61. #endif
  62. #ifdef delch
  63. inline int (delch)()  { return delch(); }
  64. #undef delch
  65. #endif
  66. #ifdef deleteln
  67. inline int (deleteln)()  { return deleteln(); }
  68. #undef deleteln
  69. #endif
  70. #ifdef erase
  71. inline int (erase)()  { return erase(); }
  72. #undef erase
  73. #endif
  74. #ifdef flushok
  75. inline int (flushok)(WINDOW* _win, int _bf)  { return flushok(_win, _bf); }
  76. #undef flushok
  77. #else
  78. #define _no_flushok
  79. #endif
  80. #ifdef getch
  81. inline int (getch)()  { return getch(); }
  82. #undef getch
  83. #endif
  84. #ifdef getstr
  85. inline int (getstr)(char *_str)  { return getstr(_str); }
  86. #undef getstr
  87. #endif
  88. #ifdef getyx
  89. inline void (getyx)(WINDOW* win, int& y, int& x) { getyx(win, y, x); }
  90. #undef getyx
  91. #endif
  92. #ifdef inch
  93. inline int (inch)()  { return inch(); }
  94. #undef inch
  95. #endif
  96. #ifdef insch
  97. inline int (insch)(char c)  { return insch(c); }
  98. #undef insch
  99. #endif
  100. #ifdef insertln
  101. inline int (insertln)()  { return insertln(); }
  102. #undef insertln
  103. #endif
  104. #ifdef leaveok
  105. inline int (leaveok)(WINDOW* win, int bf)  { return leaveok(win, bf); }
  106. #undef leaveok
  107. #else
  108. extern "C" int leaveok(WINDOW* win, int bf);
  109. #endif
  110. #ifdef move
  111. inline int (move)(int x, int y)  { return move(x, y); }
  112. #undef move
  113. #endif
  114. #ifdef refresh
  115. inline int (rfresh)()  { return refresh(); }
  116. #undef refresh
  117. #endif
  118. #ifdef scrollok
  119. inline int (scrollok)(WINDOW* win, int bf)  { return scrollok(win, bf); }
  120. #undef scrollok
  121. #else
  122. #ifndef hpux
  123. extern "C" int scrollok(WINDOW*, int);
  124. #else
  125. extern "C" int scrollok(WINDOW*, char);
  126. #endif
  127. #endif
  128. #ifdef standend
  129. inline int (standend)()  { return standend(); }
  130. #undef standend
  131. #endif
  132. #ifdef standout
  133. inline int (standout)()  { return standout(); }
  134. #undef standout
  135. #endif
  136. #ifdef wstandend
  137. inline int (wstandend)(WINDOW *win)  { return wstandend(win); }
  138. #undef wstandend
  139. #endif
  140. #ifdef wstandout
  141. inline int (wstandout)(WINDOW *win)  { return wstandout(win); }
  142. #undef wstandout
  143. #endif
  144. #ifdef winch
  145. inline int (winch)(WINDOW* win) { return winch(win); }
  146. #undef winch
  147. #endif
  148.  
  149. #ifdef mvwaddch
  150. inline int (mvwaddch)(WINDOW *win, int y, int x, char ch)
  151. { return mvwaddch(win, y, x, ch); }
  152. #undef mvwaddch
  153. #endif
  154. #ifdef mvwaddstr
  155. inline int (mvwaddstr)(WINDOW *win, int y, int x, const char * str)
  156. { return mvwaddstr(win, y, x, (char*)str); }
  157. #undef mvwaddstr
  158. #endif
  159. #ifdef mvwdelch
  160. inline int (mvwdelch)(WINDOW *win, int y, int x) { return mvwdelch(win, y, x);}
  161. #undef mvwdelch
  162. #endif
  163. #ifdef mvwgetch
  164. inline int (mvwgetch)(WINDOW *win, int y, int x) { return mvwgetch(win, y, x);}
  165. #undef mvwgetch
  166. #endif
  167. #ifdef mvwgetstr
  168. inline int (mvwgetstr)(WINDOW *win, int y, int x, char *str)
  169. {return mvwgetstr(win,y,x, str);}
  170. #undef mvwgetstr
  171. #endif
  172. #ifdef mvwinch
  173. inline int (mvwinch)(WINDOW *win, int y, int x) { return mvwinch(win, y, x);}
  174. #undef mvwinch
  175. #endif
  176. #ifdef mvwinsch
  177. inline int (mvwinsch)(WINDOW *win, int y, int x, char c)
  178. { return mvwinsch(win, y, x, c); }
  179. #undef mvwinsch
  180. #endif
  181.  
  182. #ifdef mvaddch
  183. inline int (mvaddch)(int y, int x, char ch)
  184. { return mvaddch(y, x, ch); }
  185. #undef mvaddch
  186. #endif
  187. #ifdef mvaddstr
  188. inline int (mvaddstr)(int y, int x, const char * str)
  189. { return mvaddstr(y, x, (char*)str); }
  190. #undef mvaddstr
  191. #endif
  192. #ifdef mvdelch
  193. inline int (mvdelch)(int y, int x) { return mvdelch(y, x);}
  194. #undef mvdelch
  195. #endif
  196. #ifdef mvgetch
  197. inline int (mvgetch)(int y, int x) { return mvgetch(y, x);}
  198. #undef mvgetch
  199. #endif
  200. #ifdef mvgetstr
  201. inline int (mvgetstr)(int y, int x, char *str) {return mvgetstr(y, x, str);}
  202. #undef mvgetstr
  203. #endif
  204. #ifdef mvinch
  205. inline int (mvinch)(int y, int x) { return mvinch(y, x);}
  206. #undef mvinch
  207. #endif
  208. #ifdef mvinsch
  209. inline int (mvinsch)(int y, int x, char c)
  210. { return mvinsch(y, x, c); }
  211. #undef mvinsch
  212. #endif
  213.  
  214. /*
  215.  *
  216.  * C++ class for windows.
  217.  *
  218.  *
  219.  */
  220.  
  221. class CursesWindow 
  222. {
  223. protected:
  224.   static int     count;           // count of all active windows:
  225.                                   //   We rely on the c++ promise that
  226.                                   //   all otherwise uninitialized
  227.                                   //   static class vars are set to 0
  228.  
  229.   WINDOW *       w;               // the curses WINDOW
  230.  
  231.   int            alloced;         // true if we own the WINDOW
  232.  
  233.   CursesWindow*  par;             // parent, if subwindow
  234.   CursesWindow*  subwins;         // head of subwindows list
  235.   CursesWindow*  sib;             // next subwindow of parent
  236.  
  237.   void           kill_subwindows(); // disable all subwindows
  238.  
  239. public:
  240.                  CursesWindow(WINDOW* &window);   // useful only for stdscr
  241.  
  242.                  CursesWindow(int lines,          // number of lines
  243.                               int cols,           // number of columns
  244.                               int begin_y,        // line origin
  245.                               int begin_x);       // col origin
  246.  
  247.                  CursesWindow(CursesWindow& par,  // parent window
  248.                               int lines,          // number of lines
  249.                               int cols,           // number of columns
  250.                               int by,             // absolute or relative
  251.                               int bx,             //   origins:
  252.                               char absrel = 'a'); // if `a', by & bx are
  253.                                                   // absolute screen pos,
  254.                                                   // else if `r', they are
  255.                                                   // relative to par origin
  256.                 ~CursesWindow();
  257.  
  258. // terminal status
  259.   int            lines(); // number of lines on terminal, *not* window
  260.   int            cols();  // number of cols  on terminal, *not* window
  261.  
  262. // window status
  263.   int            height(); // number of lines in this window
  264.   int            width();  // number of cols in this window
  265.   int            begx();   // smallest x coord in window
  266.   int            begy();   // smallest y coord in window
  267.   int            maxx();   // largest  x coord in window
  268.   int            maxy();   // largest  x coord in window
  269.  
  270. // window positioning
  271.   int            move(int y, int x);
  272.  
  273. // coordinate positioning
  274.   void           getyx(int& y, int& x);
  275.   int            mvcur(int sy, int ey, int sx, int ex);
  276.  
  277. // input
  278.   int            getch();
  279.   int            getstr(char * str);
  280.   int            scanw(const char *, ...);
  281.  
  282. // input + positioning
  283.   int            mvgetch(int y, int x);
  284.   int            mvgetstr(int y, int x, char * str);
  285.   int            mvscanw(int, int, const char*, ...);
  286.  
  287. // output
  288.   int            addch(const char ch);
  289.   int            addstr(const char * str);
  290.   int            printw(const char * fmt, ...);
  291.   int            inch();
  292.   int            insch(char c);
  293.   int            insertln();
  294.  
  295. // output + positioning
  296.   int            mvaddch(int y, int x, char ch);
  297.   int            mvaddstr(int y, int x, const char * str);
  298.   int            mvprintw(int y, int x, const char * fmt, ...);
  299.   int            mvinch(int y, int x);
  300.   int            mvinsch(int y, int x, char ch);
  301.  
  302. // borders
  303.   int            box(char vert, char  hor);
  304.  
  305. // erasure
  306.   int            erase();
  307.   int            clear();
  308.   int            clearok(int bf);
  309.   int            clrtobot();
  310.   int            clrtoeol();
  311.   int            delch();
  312.   int            mvdelch(int y, int x);
  313.   int            deleteln();
  314.  
  315. // screen control
  316.   int            scroll();
  317.   int            scrollok(int bf);
  318.   int            touchwin();
  319.   int            refresh();
  320.   int            leaveok(int bf);
  321. #ifndef _no_flushok
  322.   int            flushok(int bf);
  323. #endif
  324.   int            standout();
  325.   int            standend();
  326.  
  327. // multiple window control
  328.   int            overlay(CursesWindow &win);
  329.   int            overwrite(CursesWindow &win);
  330.  
  331.  
  332. // traversal support
  333.   CursesWindow*  child();
  334.   CursesWindow*  sibling();
  335.   CursesWindow*  parent();
  336. };
  337.  
  338.  
  339. inline int CursesWindow::begx()
  340. {
  341.   return w->_begx;
  342. }
  343.  
  344. inline int CursesWindow::begy()
  345. {
  346.   return w->_begy;
  347. }
  348.  
  349. inline int CursesWindow::maxx()
  350. {
  351.   return w->_maxx;
  352. }
  353.  
  354. inline int CursesWindow::maxy()
  355. {
  356.   return w->_maxy;
  357. }
  358.  
  359. inline int CursesWindow::height()
  360. {
  361.   return maxy() - begy() + 1;
  362. }
  363.  
  364. inline int CursesWindow::width()
  365. {
  366.   return maxx() - begx() + 1;
  367. }
  368.  
  369. inline int CursesWindow::box(char vert, char  hor)    
  370. {
  371.   return ::box(w, vert, hor); 
  372. }
  373.  
  374. inline int CursesWindow::overlay(CursesWindow &win)         
  375. {
  376.   return ::overlay(w, win.w); 
  377. }
  378.  
  379. inline int CursesWindow::overwrite(CursesWindow &win)       
  380. {
  381.   return ::overwrite(w, win.w); 
  382. }
  383.  
  384. inline int CursesWindow::scroll()                     
  385. {
  386.   return ::scroll(w); 
  387. }
  388.  
  389.  
  390. inline int CursesWindow::touchwin()                   
  391. {
  392.   return ::touchwin(w); 
  393. }
  394.  
  395. inline int CursesWindow::addch(const char ch)         
  396. {
  397.   return ::waddch(w, ch); 
  398. }
  399.  
  400. inline int CursesWindow::addstr(const char * str)     
  401. {
  402.   // The (char*) cast is to hack around prototypes in curses.h that
  403.   // have const missing in the parameter lists.  [E.g. SVR4]
  404.   return ::waddstr(w, (char*)str); 
  405. }
  406.  
  407. inline int CursesWindow::clear()                      
  408. {
  409.   return ::wclear(w); 
  410. }
  411.  
  412. inline int CursesWindow::clrtobot()                   
  413. {
  414.   return ::wclrtobot(w); 
  415. }
  416.  
  417. inline int CursesWindow::clrtoeol()                   
  418. {
  419.   return ::wclrtoeol(w); 
  420. }
  421.  
  422. inline int CursesWindow::delch()                      
  423. {
  424.   return ::wdelch(w); 
  425. }
  426.  
  427. inline int CursesWindow::deleteln()                   
  428. {
  429.   return ::wdeleteln(w); 
  430. }
  431.  
  432. inline int CursesWindow::erase()                      
  433. {
  434.   return ::werase(w); 
  435. }
  436.  
  437. inline int CursesWindow::getch()                      
  438. {
  439.   return ::wgetch(w); 
  440. }
  441.  
  442. inline int CursesWindow::getstr(char * str)           
  443. {
  444.   return ::wgetstr(w, str); 
  445. }
  446.  
  447. inline int CursesWindow::inch()                       
  448. {
  449.   return winch(w); 
  450. }
  451.  
  452. inline int CursesWindow::insch(char c)               
  453. {
  454.   return ::winsch(w, c); 
  455. }
  456.  
  457. inline int CursesWindow::insertln()                   
  458. {
  459.   return ::winsertln(w); 
  460. }
  461.  
  462. inline int CursesWindow::move(int y, int x)           
  463. {
  464.   return ::wmove(w, y, x); 
  465. }
  466.  
  467.  
  468. inline int CursesWindow::mvcur(int sy, int ey, int sx, int ex)
  469. {
  470.   return ::mvcur(sy, ey, sx,ex);
  471. }
  472.  
  473. inline int CursesWindow::mvaddch(int y, int x, char ch)
  474. {
  475.   return (::wmove(w, y, x)==ERR) ? ERR : ::waddch(w, ch);
  476. }
  477.  
  478. inline int CursesWindow::mvgetch(int y, int x)
  479. {
  480.   return (::wmove(w, y, x)==ERR) ? ERR : ::wgetch(w);
  481. }
  482.  
  483. inline int CursesWindow::mvaddstr(int y, int x, const char * str)
  484. {
  485.   return (::wmove(w, y, x)==ERR) ? ERR : ::waddstr(w, (char*)str);
  486. }
  487.  
  488. inline int CursesWindow::mvgetstr(int y, int x, char * str)
  489. {
  490.   return (::wmove(w, y, x)==ERR) ? ERR : ::wgetstr(w, str);
  491. }
  492.  
  493. inline int CursesWindow::mvinch(int y, int x)
  494. {
  495.   return (::wmove(w, y, x)==ERR) ? ERR : ::winch(w);
  496. }
  497.  
  498. inline int CursesWindow::mvdelch(int y, int x)
  499. {
  500.   return (::wmove(w, y, x)==ERR) ? ERR : ::wdelch(w);
  501. }
  502.  
  503. inline int CursesWindow::mvinsch(int y, int x, char ch)
  504. {
  505.   return (::wmove(w, y, x)==ERR) ? ERR : ::winsch(w, ch);
  506. }
  507.  
  508. inline int CursesWindow::refresh()                   
  509. {
  510.   return ::wrefresh(w); 
  511. }
  512.  
  513. inline int CursesWindow::clearok(int bf)             
  514. {
  515.   return ::clearok(w,bf); 
  516. }
  517.  
  518. inline int CursesWindow::leaveok(int bf)             
  519. {
  520.   return ::leaveok(w,bf); 
  521. }
  522.  
  523. inline int CursesWindow::scrollok(int bf)            
  524. {
  525.   return ::scrollok(w,bf); 
  526. }
  527.  
  528. #ifndef _no_flushok
  529. inline int CursesWindow::flushok(int bf)            
  530. {
  531.   return ::flushok(w, bf); 
  532. }
  533. #endif
  534.  
  535. inline void CursesWindow::getyx(int& y, int& x)       
  536. {
  537.   ::getyx(w, y, x); 
  538. }
  539.  
  540. inline int CursesWindow::standout()                   
  541. {
  542.   return ::wstandout(w); 
  543. }
  544.  
  545. inline int CursesWindow::standend()                   
  546. {
  547.   return ::wstandend(w); 
  548. }
  549.  
  550. inline int CursesWindow::lines()                      
  551. {
  552.   return LINES; 
  553. }
  554.  
  555. inline int CursesWindow::cols()                       
  556. {
  557.   return COLS; 
  558. }
  559.  
  560. inline CursesWindow* CursesWindow::child()
  561. {
  562.   return subwins;
  563. }
  564.  
  565. inline CursesWindow* CursesWindow::parent()
  566. {
  567.   return par;
  568. }
  569.  
  570. inline CursesWindow* CursesWindow::sibling()
  571. {
  572.   return sib;
  573. }
  574.  
  575. #endif /* _G_HAVE_CURSES */
  576. #endif
  577.